package com.saltedfish.tool.ui.flag.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.saltedfish.tool.R;
import com.saltedfish.tool.model.DayTable;
import com.saltedfish.tool.model.WeekInfo;
import com.saltedfish.tool.ui.calendar.CalendarAdapter;
import com.saltedfish.tool.util.UIUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import cn.droidlover.xdroidmvp.base.SimpleListener;
import cn.droidlover.xdroidmvp.log.XLog;


public class SelectWeekAdapter extends BaseQuickAdapter<WeekInfo, BaseViewHolder> {

    private SimpleListener listener;

    private Context mContext;

    private int selectPosition = 0;

    private int widths = 0;


    private List<WeekInfo> weekInfos;

    public void setListener(SimpleListener listener) {
        this.listener = listener;
    }

    public SelectWeekAdapter(List<WeekInfo> data, Context context,int widths) {
        super(R.layout.layout_select_week, data);
        this.mContext = context;
        this.weekInfos = data;
        this.widths = widths;
    }

    public void setWeekList(List<WeekInfo> weekInfo){
        this.weekInfos = weekInfo;
        notifyDataSetChanged();
    }


    @Override
    protected void convert(BaseViewHolder helper, final WeekInfo weekInfo) {
        TextView viewSelect = helper.getView(R.id.view_select);
        RelativeLayout releate_week = helper.getView(R.id.releate_week);
        viewSelect.setText(weekInfo.week);
        int position = helper.getAdapterPosition();
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.width = widths;
        layoutParams.height = widths;
//        XLog.e("-----width---11--"+width);
        releate_week.setLayoutParams(layoutParams);
        if(weekInfos.get(position).flag){
            viewSelect.setTextColor(mContext.getResources().getColor(R.color.color_white));
            viewSelect.setBackgroundResource(R.drawable.shape_radius_3097_whitle);
        }else{
            viewSelect.setTextColor(mContext.getResources().getColor(R.color.color_333333));
            viewSelect.setBackgroundResource(R.drawable.shape_radius_white_e1e4);
        }

        viewSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener !=null){
                    listener.onClick(position);
                   // setSelectPosition(position);
                    notifyDataSetChanged();
                }
            }
        });


    }


}
